package com.jichangxiu.common.entity.bo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;

/**
 * SecurityRole:
 *
 * @author Jcx
 * @create 2023-04-03 21:49
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "系统安全角色")
public class SecurityRole implements GrantedAuthority {

    @Schema(description = "系统角色对象")
    private Record record;

    @Override
    @JsonIgnore
    public String getAuthority() {
        String roleCode = record.getStr("roleCode");
        return roleCode.startsWith("ROLE_") ? roleCode : "ROLE_" + roleCode;
    }

    public String getRoleId() {
        return record.getStr("roleId");
    }

    public boolean getIsPlatform() {
        return record.getBoolean("isPlatform");
    }

    public String getDataScope() {
        return record.getStr("dataScope");
    }

}
